package ConvertPDF;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

import javax.swing.*;

public class ConvertPDF_UI extends JFrame implements ActionListener {

	private JLabel mLable;
	private JButton mExportButton;
	private JButton mImportButton;
	private JTextField mTextField;
	private JFileChooser mFileChooser;
	private String path, page;
	private Data data;
	private WriteXMLFile writeXMLFile;
	
	public ConvertPDF_UI(){
		initUI();
		data = new Data();
		writeXMLFile = new WriteXMLFile();
	}
	
	private void initUI(){
		mLable = new JLabel("URL");
		mExportButton = new JButton("Export");
		mImportButton = new JButton("Import");
		mTextField = new JTextField(25);
		mFileChooser = new JFileChooser();
		this.add(mLable);
		this.add(mTextField);
		this.add(mImportButton);
		this.add(mExportButton);
		
		//su kien
		mImportButton.addActionListener(this);
		mExportButton.addActionListener(this);
		
	}
	
	public static void buildGUI() {
        ConvertPDF_UI app = new ConvertPDF_UI();
        app.setLayout(new FlowLayout());
        app.setSize(200, 225);
        app.setVisible(true);
        app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        
    }
	
	public String getPath(){
		
		return path;
	}

	//event button
	public void actionPerformed(ActionEvent e) {
		
		
		//su kien cua nut import
		if(e.getSource() == mImportButton){
			int returnval = mFileChooser.showOpenDialog(ConvertPDF_UI.this);
			
			//neu file duoc chon
			if(returnval == JFileChooser.APPROVE_OPTION){
				File selectFile = mFileChooser.getSelectedFile();
				path = selectFile.getPath();
				data.getPath(path);
				page = data.ReadPdfFile();
				
				writeXMLFile.CreateXMLFile(page);
			}
		}
		
	}
	
	
}
